package com.cby.jetpack.sample.binding

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.cby.jetpack.sample.R
import com.cby.jetpack.sample.binding.data.ImageInfo
import com.cby.jetpack.sample.binding.listener.MyOnClickListener
import com.cby.jetpack.sample.databinding.ActivityDataBindListenerBinding
import com.cby.jetpack.sample.ext.dataBinding
import com.cby.jetpack.sample.ext.showToast

/**
 * @description: TestDataBindingListenerActivity
 *
 * @author ChenBaoyang
 * @date 8/10/21 14:33
 */
class TestDataBindingListenerActivity : AppCompatActivity(), MyOnClickListener{

    private val url = "https://ae01.alicdn.com/kf/U76a18e0d315e407a8daf3d91de033e31i.jpg"

    //通过委托的方式（lazy），一定要在onCreate或者onStart调用下binding，不然无法加载处view（即setContentView没有触发）
    private val binding: ActivityDataBindListenerBinding by dataBinding(R.layout.activity_data_bind_listener)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding.listener = this@TestDataBindingListenerActivity
    }

    override fun onClick() {
        val image = ImageInfo("美女图片", url)
        binding.imageInfo = image
        showToast("onClick")
    }
}